import {createRouter, createWebHistory} from "vue-router";
import Home from "../views/Home.vue";

const routes = [
    {
        path: '/',
        redirect: '/login'
    }, {
        path: "/",
        name: "Home",
        component: Home,
        children: [
            {
                path: "/dashboard",
                name: "dashboard",
                meta: {
                    title: '首页'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/1.FirstPage/Dashboard.vue")
            },
            
            {
                path: "/table",
                name: "basetable",
                meta: {
                    title: '货品管理'
                },
                component: () => import ( /* webpackChunkName: "table" */ "../views/2.Goods/BaseTable.vue")
            },
            
            
            {
                path: "/query2",
                name: "query2",
                meta: {
                    title: '收发存汇总'
                },
                component: () => import ( /* webpackChunkName: "table" */ "../views/11.Query/query.vue")
            },
            {
                path: "/query1",
                name: "query1",
                meta: {
                    title: '库存查询'
                },
                component: () => import ( /* webpackChunkName: "table" */ "../views/3.Query/3.1.vue")
            },
                        
            {
                path: "/out1",
                name: "out1",
                meta: {
                    title: '出库查询'
                },
                component: () => import("../views/4.Out/OutTable.vue")
                
            },
            
             {
                path: "/out2",
                name: "out2",
                meta: {
                    title: '出库记录'
                },
                  component: () => import( /* webpackChunkName: "form" */ "../views/4.Out/OutRecord.vue")
                
            },
            {
                path: "/out3",
                name: "out3",
                meta: {
                    title: '出库柱状图分析'
                },
                  component: () => import( /* webpackChunkName: "form" */ "../views/4.Out/Graphics.vue")
                
            },
            {
                path: "/out4",
                name: "out4",
                meta: {
                    title: '出库饼图分析'
                },
                  component: () => import( /* webpackChunkName: "form" */ "../views/4.Out/Pie.vue")
                
            },
            {
                path: "/out5",
                name: "out5",
                meta: {
                    title: '出库散点图分析'
                },
                  component: () => import( /* webpackChunkName: "form" */ "../views/4.Out/ScatterPlot.vue")
                
            },
            
          
            
            {
                path: "/in1",
                name: "in1",
                meta: {
                    title: '入库单'
                },
                component: () => import ( /* webpackChunkName: "form" */ "../views/5.In/1.vue")
            },
            {
                path: "/in2",
                name: "in2",
                meta: {
                    title: '入库记录'
                },
                component: () => import ( /* webpackChunkName: "form" */ "../views/5.In/4.1.1.vue")
            },
            
            {
                path: "/in3",
                name: "in3",
                meta: {
                    title: '新增货品'
                },
                component: () => import ( /* webpackChunkName: "form" */ "../views/5.In/4.1.2.vue")
            },
            {
                path: "/analyse1",
                name: "analyse1",
                meta: {
                    title: '超储分析'
                },
                component: () => import ( /* webpackChunkName: "form" */ "../views/6.Analyse/5.2.1.vue")
            },            {
                path: "/analyse2",
                name: "analyse2",
                meta: {
                    title: '低储分析'
                },
                component: () => import ( /* webpackChunkName: "form" */ "../views/6.Analyse/5.2.2.vue")
            },
            {
                path: '/translation',
                name: 'translation',
                meta: {
                    title: '翻译',
                   
                },
                component: () => import ( '../views/8.Translation/translation.vue')
            },

             {
                path: "/clock1",
                name: "clock1",
                meta: {
                    title: '员工日常打卡'
                },
                component: () => import ("../views/9.Clock/Clock.vue")
            },            {
                path: "/clock2",
                name: "clock2",
                meta: {
                    title: '员工打卡记录'
                },
                component: () => import ( "../views/9.Clock/ClockRecorde.vue")
            },

               

             {
                path: "/permission",
                name: "permission",
                meta: {
                    title: '权限管理',
                    permission: true
                },
                component: () => import ( /* webpackChunkName: "permission" */ "../views/7.Controll/Permission.vue")
            },  {
                path: '/404',
                name: '404',
                meta: {
                    title: '找不到页面'
                },
                component: () => import (/* webpackChunkName: "404" */ '../views/7.Controll/404.vue')
            }, {
                path: '/403',
                name: '403',
                meta: {
                    title: '没有权限'
                },
                component: () => import (/* webpackChunkName: "403" */ '../views/7.Controll/403.vue')
            }, 
             
            {
                path: "/about",
                name: "about",
                meta: {
                    title: '关于项目'
                },
                component: () => import ( "../views/10.About/about.vue")
            },
        ]
    }, {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import ( /* webpackChunkName: "login" */ "../views/Login.vue")
    }
];

const router = createRouter({
    history: createWebHistory(),
    routes
});

router.beforeEach((to,from,next)=>{
    const role1 = localStorage.getItem("ms_username");
    const role2 = localStorage.getItem("ms_slider");
    if (to.meta.permission) {
        // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
        role2 === 'true' && role1==='admin'
            ? next()
            : next('/403');
    } else {
        next();
    }
})

export default router;